package com.example.controller;

import com.example.model.PurchaseOrderQueryDTO;
import com.example.model.PurchaseOrderVO;
import com.example.model.Result;
import com.example.service.PurchaseOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 采购订单控制器
 */
@RestController
@RequestMapping("/api/purchase-order")
public class PurchaseOrderController {

    @Autowired
    private PurchaseOrderService purchaseOrderService;

    /**
     * 查询采购订单列表
     * @param queryDTO 查询条件，不传则查询所有
     * @return 采购订单列表
     */
    @PostMapping("/list")
    public Result<List<PurchaseOrderVO>> queryPurchaseOrders(@RequestBody(required = false) PurchaseOrderQueryDTO queryDTO) {
        try {
            List<PurchaseOrderVO> list = purchaseOrderService.queryPurchaseOrders(queryDTO);
            return Result.success(list);
        } catch (Exception e) {
            return Result.error("查询采购订单失败：" + e.getMessage());
        }
    }
}